package compiler.semantics;

import java.util.HashMap;

public class SymbolicTable
{
    private class SymbolInfo
    {
        public Integer address;
        public VarType type;

        public SymbolInfo(VarType type, Integer address)
        {
            this.type = type;
            this.address = address;
        }
    }

    private HashMap<String, SymbolInfo> hashTable;

    public SymbolicTable()
    {
        hashTable = new HashMap<String, SymbolInfo>();
    }

    public boolean containsKey(String key)
    {
        return hashTable.containsKey(key);
    }

    public VarType getSymbolType(String key)
    {
        return hashTable.get(key).type;
    }

    public Integer getSymbolAddress(String key)
    {
        return hashTable.get(key).address;
    }

    public SymbolInfo put(String key, VarType type)
    {
        Integer address = hashTable.size();
        return hashTable.put(key, new SymbolInfo(type, address));
    }

    public int size()
    {
        return hashTable.size();
    }
}
